#include "clkMesh.h"

clkMesh::clkMesh()
{
	m_hasMesh = false;
	m_hasTexture = false;
}

clkMesh::~clkMesh()
{

}

void clkMesh::initMesh(
	char* a_meshPath,
	V3DF  a_cen,
	V3DF  a_trn,
	V3DF  a_scl,
	V3DF  a_rot)
{
	m_d3d->createMesh(&m_mesh,a_meshPath);
	
	m_cen = a_cen;
	m_trn = a_trn;
	m_scl = a_scl;
	m_rot = a_rot;

	m_look.set(0,0,1);
	m_right.set(1,0,0);

	if(m_mesh.m_meshId != -1)
		m_hasMesh = true;
}

void clkMesh::initTexture(char* a_texturePath)
{
	m_d3d->createTexture2D(&m_texture,a_texturePath);

	if(m_texture.m_texId != -1)
		m_hasTexture = true;
}

void clkMesh::update()
{
	if(m_hasMesh)
	{
		m_look.set(0,0,1);
		m_right.set(1,0,0);
		m_d3d->updateTransform(&m_mesh,m_cen,m_trn,m_scl,m_rot,&m_look,&m_right);
	}
}

void clkMesh::draw()
{
	if(m_hasTexture)
		m_d3d->setTexture2D(&m_texture,0);
	else
		m_d3d->setTexture2D(0,0);

	if(m_hasMesh)
		m_d3d->drawMesh(&m_mesh);
}